package com.ruoyi.service.impl;

import java.util.List;

import com.ruoyi.domain.BasisFrequencyConverter;
import com.ruoyi.dto.BasisPositionFrequencyConverter;
import com.ruoyi.mapper.BasisFrequencyConverterMapper;
import com.ruoyi.service.IBasisFrequencyConverterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 变频器类型和变频器名称关联Service业务层处理
 * 
 * @author wangzebing
 * @date 2025-07-05
 */
@Service
public class BasisFrequencyConverterServiceImpl implements IBasisFrequencyConverterService
{
    @Autowired
    private BasisFrequencyConverterMapper basisFrequencyConverterMapper;

    /**
     * 查询变频器类型和变频器名称关联
     * 
     * @param id 变频器类型和变频器名称关联主键
     * @return 变频器类型和变频器名称关联
     */
    @Override
    public BasisFrequencyConverter selectBasisFrequencyConverterById(Long id)
    {
        return basisFrequencyConverterMapper.selectBasisFrequencyConverterById(id);
    }

    /**
     * 查询变频器类型和变频器名称关联列表
     * 
     * @param basisFrequencyConverter 变频器类型和变频器名称关联
     * @return 变频器类型和变频器名称关联
     */
    @Override
    public List<BasisFrequencyConverter> selectBasisFrequencyConverterList(BasisFrequencyConverter basisFrequencyConverter)
    {
        return basisFrequencyConverterMapper.selectBasisFrequencyConverterList(basisFrequencyConverter);
    }

    /**
     * 新增变频器类型和变频器名称关联
     * 
     * @param basisFrequencyConverter 变频器类型和变频器名称关联
     * @return 结果
     */
    @Override
    public int insertBasisFrequencyConverter(BasisFrequencyConverter basisFrequencyConverter)
    {
        BasisPositionFrequencyConverter basisPositionFrequencyConverter = new BasisPositionFrequencyConverter();
        int i = basisFrequencyConverterMapper.insertBasisFrequencyConverter(basisFrequencyConverter);
        if (i>0){
            basisPositionFrequencyConverter.setFrequencyConverterId(Math.toIntExact(basisFrequencyConverter.getId()));
            basisPositionFrequencyConverter.setLoadingId(basisFrequencyConverter.getLoadingId());
            basisPositionFrequencyConverter.setPositionId(basisFrequencyConverter.getPositionId());
            basisFrequencyConverterMapper.addBasisPositionFrequencyConverter(basisPositionFrequencyConverter);
        }
        return i;
    }

    /**
     * 修改变频器类型和变频器名称关联
     * 
     * @param basisFrequencyConverter 变频器类型和变频器名称关联
     * @return 结果
     */
    @Override
    public int updateBasisFrequencyConverter(BasisFrequencyConverter basisFrequencyConverter)
    {
        return basisFrequencyConverterMapper.updateBasisFrequencyConverter(basisFrequencyConverter);
    }

    /**
     * 批量删除变频器类型和变频器名称关联
     * 
     * @param ids 需要删除的变频器类型和变频器名称关联主键
     * @return 结果
     */
    @Override
    public int deleteBasisFrequencyConverterByIds(Long[] ids)
    {
        return basisFrequencyConverterMapper.deleteBasisFrequencyConverterByIds(ids);
    }

    /**
     * 删除变频器类型和变频器名称关联信息
     * 
     * @param id 变频器类型和变频器名称关联主键
     * @return 结果
     */
    @Override
    public int deleteBasisFrequencyConverterById(Long id)
    {
        return basisFrequencyConverterMapper.deleteBasisFrequencyConverterById(id);
    }

    @Override
    public int deleteBasisFrequencyConverterById2(BasisPositionFrequencyConverter basisPositionFrequencyConverter) {

        int i = basisFrequencyConverterMapper.deleteBasisFrequencyConverterById(basisPositionFrequencyConverter.getFrequencyConverterId().longValue());
        if (i > 0 ){
            boolean b = basisFrequencyConverterMapper.delBasisPositionFrequencyConverter(basisPositionFrequencyConverter);
            if (!b) return 0;
        }

        return i;
    }

    @Override
    public List<BasisFrequencyConverter> findByLoadingIdAndPositionId(String loadingId, String positionId) {
        return basisFrequencyConverterMapper.findByLoadingIdAndPositionId(loadingId, positionId);
    }
}
